package com.lonwin.inspectionmanagement.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.app.utils.TimeUtils;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.SortOutBean;
import com.lonwin.inspectionmanagement.mvp.ui.activity.CreatPointRecordActivity;

import java.util.List;

public class SortOutRecordItemItem1Adapter extends BaseQuickAdapter<SortOutBean.DataBean.RecordsBean.QuestTempDtosBean,BaseViewHolder> {
    public SortOutRecordItemItem1Adapter(@Nullable List<SortOutBean.DataBean.RecordsBean.QuestTempDtosBean> data) {
        super(R.layout.sortout_record_item_item_item1,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SortOutBean.DataBean.RecordsBean.QuestTempDtosBean item) {
        String title=((item.getQusetTypeTempRel()!=null&&item.getQusetTypeTempRel().size()>0)?item.getQusetTypeTempRel().get(0).getQuestTypenm():"")+"（"+item.getAddr()+"）";
        helper.setText(R.id.sortout_record_item_item_item1_type,title)
                .setText(R.id.sortout_record_item_item_item1_time,TimeUtils.dateForStr(item.getSystm()).substring(5,16));
//        1、已整理列表-问题：已交办、已提交只能操作一次，操作后按钮隐藏，2个按钮都操作完“编辑”变成“查看”
//        2、已整理列表-轨迹：提交只能操作一次，操作后按钮隐藏，“编辑”变成“查看”

        if (item.getEventflag()==0)
            {
                helper.<TextView>getView(R.id.sortout_record_item_item_item1_usered).setVisibility(View.VISIBLE);
            helper.setText(R.id.sortout_record_item_item_item1_statue,"未交办");
                helper.<TextView>getView(R.id.sortout_record_item_item_item1_statue).setBackgroundResource(R.drawable.listbutton_gray_bg_select);
                helper.<TextView>getView(R.id.sortout_record_item_item_item1_usered).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CreatPointRecordActivity.startCreatPointActivity(mContext,item.getQuestid(), CreatPointRecordActivity.Type.HANDOVER,"交办问题");
                    }
                });
            }else {
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_usered).setVisibility(View.GONE);
            helper.setText(R.id.sortout_record_item_item_item1_statue,"已交办");
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_statue).setBackgroundResource(R.drawable.listbutton_blue_bg_select);
        }
        //0表示未提价事件，1成功提交到事件eventid这个是时间的id,你可能用不到
        if (item.getOpened()==0)
        {
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_useredtj).setVisibility(View.VISIBLE);
            helper.setText(R.id.sortout_record_item_item_item1_tjstatus,"未提交");
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_tjstatus).setBackgroundResource(R.drawable.listbutton_gray_bg_select);
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_useredtj).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CreatPointRecordActivity.startCreatPointActivity(mContext,item.getQuestid(), CreatPointRecordActivity.Type.PUB,"提交问题");
                }
            });
        }else {
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_useredtj).setVisibility(View.GONE);
            helper.setText(R.id.sortout_record_item_item_item1_tjstatus,"已提交");
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_tjstatus).setBackgroundResource(R.drawable.listbutton_blue_bg_select);
        }
        if (item.getEventflag()!=0&&item.getOpened()!=0)
        {
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_edit).setText("查看");
        }else {
            helper.<TextView>getView(R.id.sortout_record_item_item_item1_edit).setText("编辑");

        }


        helper.<TextView>getView(R.id.sortout_record_item_item_item1_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.getOpened()==0||item.getEventflag()==0)
                {
                    CreatPointRecordActivity.startCreatPointActivity(mContext,item.getQuestid(), CreatPointRecordActivity.Type.EDIT,"编辑问题记录");
                }else {
                    CreatPointRecordActivity.startCreatPointActivity(mContext,item.getQuestid(), CreatPointRecordActivity.Type.LOOK,"查看问题记录");

                }
            }
        });
    }

}
